package com.caiju.health.service.impl;

import com.caiju.health.dto.OrderSettingDTO;
import com.caiju.health.mapper.IOrderSettingMapper;
import com.caiju.health.pojo.OrderSetting;
import com.caiju.health.service.IOrderSettingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.*;

@Service
public class IOrderSettingServiceImpl implements IOrderSettingService {

    @Resource
    private IOrderSettingMapper orderSettingMapper;

    @Override
    public void addBatchOrderSetting(ArrayList<OrderSettingDTO> orderSettingDTOS) {
        for (OrderSettingDTO orderSettingDTO :orderSettingDTOS) {
                orderSettingMapper.insertOrderSetting(orderSettingDTO);
        }
    }

    @Override
    public List<OrderSettingDTO> findOrderSettingListByOrderDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH)+1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        String startTime = year + "-" + month + "-" + day;

        day = 31;
        String endTime = year + "-" + month + "-" + day;

        HashMap<Object,Object> map = new HashMap<>();
        map.put("startTime",startTime);
        map.put("endTime",endTime);
        List<OrderSetting> orderSettingList = orderSettingMapper.findOrderSettingListByOrderDate(map);
        ArrayList<OrderSettingDTO> orderSettingDTOS =  new ArrayList<>();
        for (OrderSetting orderSetting:orderSettingList) {
            OrderSettingDTO orderSettingDTO = new OrderSettingDTO() ;
            calendar.setTime(orderSetting.getOrderDate()) ;
            orderSettingDTO.setDate(calendar.get(Calendar.DAY_OF_MONTH)+"");
            orderSettingDTO.setNumber(orderSetting.getNumber());
            orderSettingDTO.setReservations(orderSetting.getReservations());
            orderSettingDTOS.add(orderSettingDTO);


        }





        return orderSettingDTOS;
    }

    @Override
    public void updateOrderSettingByOrderDate(String newDate, Integer value) {
        orderSettingMapper.updateOrderSettingByOrderDate(newDate,value);
    }
}
